package com.zsr.example.schedule;


import com.zsr.example.service.StatisticsDailyService;
import com.zsr.example.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务 [生成统计数据]
 * @author zsr
 * @date 2021/6/25 23:52
 */
@Component
public class ScheduledTask {
    @Autowired
    private StatisticsDailyService staService;

    /**
     * cron 在每天凌晨0点，把前一天数据进行查询添加
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void task1(){
        staService.createStatisticsByDay(DateUtil.formatDate(DateUtil.addDays(new Date(),-1)),true);
    }

}
